import { observable, action, autorun,toJS } from 'mobx';
import * as  Apis from '../apis/govern';
import {message} from 'antd';

export default class governorStore {
    @observable cid = 0;
    @observable pagesize = 5;
    @observable categoryList = [];
    @observable allCount = 0;
    @observable taskList = [];
    @observable total = 0;
    @observable current = 1;
    @observable flowid = 0;
    @observable titles = {};
    @observable projectLink = '';
    @observable taskLink = '';
    @observable activeKey = "0";
    @observable showSearchAd = false;
    @observable searchData ={ name: "", source: "", sourceObj: [], responsible: "", responsibleObj: [], leaders: "", leadersObj: [], status: "0" };
    @observable dateselect = ["0"];
    @action
    getCateGory = (params) => {
        Apis.getCateGory(params).then( params => {
              if(parseInt(params.status) == 1){
                this.categoryList = params.categoryList;
                this.allCount = params.allCount;
                this.flowid = params.flowid
              }else{
                message.error(params.error);
              }
          }).catch(error => {
              message.error(error);
          });
    }
    @action
    getTableTitle = (params) => {
        Apis.getTableTitle(params).then( params => {
            if(parseInt(params.status) == 1){
              this.titles = params.titles
            }else{
              message.error(params.error);
            }
        }).catch(error => {
            message.error(error);
        });
    }
    @action
    getGovernorList = (params) => {
        Apis.getGovernorList(params).then( params => {
            if(parseInt(params.status) == 1){
              this.taskList = params.taskList;
              this.total = params.total;
              this.current = params.current;
              this.pagesize = params.pagesize;
              this.projectLink = params.projectLink;
              this.taskLink = params.taskLink
            }else{
              message.error(params.error);
            }
        }).catch(error => {
            message.error(error);
        });
    }
    @action
    changeTab = (key) => {
        this.activeKey = key;
    }
    @action
    selChange = (v) => {
        this.searchData.status = v;
    }
    @action
    reSet = () => {
        this.searchData = { name: "", source: "", sourceObj: [], responsible: "", responsibleObj: [], leaders: "", leadersObj: [], status: "0" };
        this.dateselect = ["0"];
    }
    @action
    showSearch = (bool) => {
        this.showSearchAd = bool;
    }
    @action
    dateGroupChange = (v) => {
        this.dateselect = v;
    }
    @action
    changeSearchData = (key, value) => {
        this.searchData[key] = value;
    }
    @action
    changeBrowser = (id, d1, d2) => {
        this.searchData[id] = d1;
        this.searchData[id + "Obj"] = d2;
    }

}
